//Wednesday, October 28 2009
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class PouringWater
{
	public:
		int getMinBottles(int N, int K)
		{
			unsigned n = N;
			while (bottlesRemaining(n) > K)
				++n;
			return n - N;
		}
		int bottlesRemaining(unsigned n)
		{
			int nBottles = 0;
			while (n > 0)
			{
				nBottles += n % 2;
				n /= 2;
			}
			return nBottles;
		}

};
